// pages/my/my.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        islogin:'1',//控制登录、找回密码、注册的控制量
        loginbtnstate:'true',
        registeriphone:'',
        registerpassword:'',
        comebackpassword:'',
        strloginUser:'',
        strloginpassword:'',
        switchChecked:''
    },
    //获取是否记住密码的状态值
    bindswitchChange:function(e){
        console.log(e)
        var that = this
        var m = e.detail.value
        if(m==true)
        {
            that.setData({
                comebackpassword:m,
                loginbtnstate:false
            })
        }
        else if(m=false)
        {
            that.setData({
                switchChecked:m,
            })
        }
        console.log(that.data.switchChecked+'状态')
    },
    //找回密码手机号判断
    comepass:function(e){
        console.log(e.detail.value)
        var that = this
        var m = e.detail.value
        if(m!=''&&(m.length==11))
        {
            that.setData({
                comebackpassword:m,
                loginbtnstate:false
            })
        }
        else
        {
            that.setData({
                loginbtnstate:true
            })
        }
    },
    //找回密码
    comebackpassword:function(e){
        var that=this
        var value = wx.getStorageSync('userobj2')
        if(that.data.comebackpassword==value.iphone)
        {
            wx.setClipboardData({
              data: value.password,
              success(res){
                  console.log(res.data+"密码")
                  that.setData({
                      islogin:1
                  })
                  wx.showToast({
                    title: '密码已复制',
                    duration:2000
                  })
              }
            })
        }
        else
        {
            wx.showToast({
              title: '手机号未注册',
            })
        }
    },
    //登录手机号判断
    inputipone1:function(e){
        console.log(e.detail.value)
        var that = this
        var m = e.detail.value
        if(m!=''&&(m.length==11))
        {
            that.setData({
                strloginUser:m
            })
            if(that.data.strloginpassword != '')
            {
                that.setData({
                    loginbtnstate:false
                })
            }
            else
            {
                that.setData({
                    loginbtnstate:true
                })
            }
        }
        else
        {
            that.setData({
                loginbtnstate:true
            })
        }
    },
    //登录密码判断
    password1:function(e){
        console.log(e.detail.value)
        var that = this
        var m = e.detail.value
        if(m != '')
        {
            that.setData({
                strloginpassword:m
            })
            if(that.data.strloginUser != '' &&(that.data.strloginUser.length==11))
            {
                that.setData({
                    loginbtnstate:false
                })
            }
            else{
                that.setData({
                    loginbtnstate:true
                })
            }
        }
        else{
            that.setData({
                loginbtnstate:true
            })
        }
    },
    //登录
    onlogin:function(e){
        var that = this
        if(that.data.switchChecked==true)
        {
            wx.setStorageSync('iphone1', that.data.strloginUser);
            wx.setStorageSync('password1', that.data.strloginpassword);
            wx.setStorageSync('checkedValue1', that.data.switchChecked);
            wx.setStorageSync('wxlogin1', false);
        }
        else if(that.data.switchChecked==false)
        {
            wx.setStorageSync('iphone1', "");
            wx.setStorageSync('password1', "");
            wx.setStorageSync('checkedValue1', false);
            wx.setStorageSync('wxlogin1', true);
        }
        var m = wx.getStorageSync('userobj2')
        if(that.data.strloginUser==m.iphone)
        {
            if(that.data.strloginpassword==m.password)
            {
                wx.showToast({
                  title: '登录成功',
                })
                wx.switchTab({
                  url: '../index/index',
                })
            }
            else
            {
                wx.showToast({
                  title: '密码错误',
                })
            }
        }
        else
        {
            wx.showToast({
              title: '手机号未注册',
            })
        }
    },
    //注册手机号判断
    inputipone2:function(e){
        console.log(e.detail.value)
        var that = this
        var m = e.detail.value
        if(m!=''&&(m.length==11))
        {
            that.setData({
                registeriphone:m
            })
            if(that.data.registerpassword != '')
            {
                that.setData({
                    loginbtnstate:false
                })
            }
            else
            {
                that.setData({
                    loginbtnstate:true
                })
            }
        }
        else
        {
            that.setData({
                loginbtnstate:true
            })
        }
    },
    //注册密码判断
    password2:function(e){
        console.log(e.detail.value)
        var that = this
        var m = e.detail.value
        if(m != '')
        {
            that.setData({
                registerpassword:m
            })
            if(that.data.registeriphone != '' &&(that.data.registeriphone.length==11))
            {
                that.setData({
                    loginbtnstate:false
                })
            }
            else{
                that.setData({
                    loginbtnstate:true
                })
            }
        }
        else{
            that.setData({
                loginbtnstate:true
            })
        }
    },
    //注册
    formsubmit:function(e){
        console.log(e)
        var obj={}
        obj.iphone=e.detail.value.registerinputiphone
        obj.password=e.detail.value.registerinputpassword
        wx.setStorageSync('userobj2', obj)
        wx.showToast({
          title: '注册成功',
        })
        this.setData({
            islogin:1
        })
    },
    //转到注册页面
    register:function(e){
        this.setData({
            islogin:3
        })
    },
    //转到找回密码页面
    forget:function(e){
        this.setData({
            islogin:2
        })
    },
    //转到登录界面
    denglu:function(e){
        this.setData({
            islogin:1
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        var that = this
        that.setData({
            strloginUser:wx.getStorageSync('iphone1'),
            strloginpassword:wx.getStorageSync('password1'),
            switchChecked:wx.getStorageSync('checkedValue1'),
            loginbtnstate:wx.getStorageSync('wxlogin1'),
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})